home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jkarcher@ix.netcom.com(John J. Karcher )
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Referances troubble
- Date: 21 Feb 1996 00:35:12 GMT
- Organization: Netcom
- Message-ID: <4gdpc0$9to@reader2.ix.netcom.com>
- References: <1266.6624T117T1455@himolde.no>
- NNTP-Posting-Host: ix-vf4-02.ix.netcom.com
- X-NETCOM-Date: Tue Feb 20 4:35:12 PM PST 1996
-
- In <1266.6624T117T1455@himolde.no> Espen.Berntsen@himolde.no (Nameless) writes:
- >
- >Ok, I have aslight problem with references. The problem is that I have to pass a
- >few pointers to a subroutine, where things are done to them, and then they are
- >passed back. Now, what I hoped would work was something like this
- >
-
- ..
-
- >void Tester(void &Testering)
- >{
- > printf("%i\n",Testering);
- > Testering = AllocMem(100, MEMF_CHIP|MEMF_CLEAR);
- > printf("%i\n",Testering);
- >}
- >
- >void main(void)
- >{
- > void *Test;
- >
- > printf("%i\n",Test);
- > Tester(Test);
- >
- > printf("%i\n",Test);
- >// FreeMem(Test, 100);
- >}
-
-
- There are two problems here (as far as I can tell). Try:
-
- void Tester(void **Testering) // (void &Testering) will not yield
- // the desired result
- {
- printf("%i\n",*Testering);
- *Testering = AllocMem(100, MEMF_CHIP|MEMF_CLEAR);
- printf("%i\n",*Testering);
- }
-
- void main(void)
- {
- void *Test;
-
- printf("%i\n",Test);
- Tester(&Test);
-
- printf("%i\n",Test);
- // FreeMem(Test, 100);
- }
-
- The idea here is to pass a pointer to the pointer. If you just pass
- the pointer, modifying it will have no effect on the original. By
- passing a pointer to your original pointer, modifying *Testering will
- modify the original pointer.
-
- - John J. Karcher
-
-
-